﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HaumDisplay
{
    public class HaumLine
    {
        /// <summary>
        /// 线起点
        /// </summary>
        public PointF startPoint;

        /// <summary>
        /// 线终点
        /// </summary>
        public PointF endPoint;

        private Color _selectColor;
        /// <summary>
        /// 选中颜色
        /// </summary>
        public Color selectColor
        {
            get { return _selectColor; }
        }
        
        private Color _penColor;
        /// <summary>
        /// 画笔颜色
        /// </summary>
        public Color penColor
        {
            get { return _penColor; }
            set
            {
                _penColor = value;

                int r = 255 - value.R;
                int g = 255 - value.G;
                int b = 255 - value.B;
                _selectColor = Color.FromArgb(r, g, b);
            }
        }

        private float _penSize;
        /// <summary>
        /// 画笔宽度
        /// </summary>
        public float penSize
        {
            get { return _penSize; }
            set { _penSize = value; }
        }

        /// <summary>
        /// 是否选中
        /// </summary>
        public bool isSelect;

        /// <summary>
        /// 获取最小外矩尺寸
        /// </summary>
        /// <returns></returns>
        public SizeF GetSizeF()
        {
            SizeF size = new SizeF(Math.Abs(endPoint.X - startPoint.X), Math.Abs(endPoint.Y - startPoint.Y));
            return size;
        }

        /// <summary>
        /// 获取长度
        /// </summary>
        /// <returns></returns>
        public float GetLength()
        {
            float dx = endPoint.X - startPoint.X;
            float dy = endPoint.Y - startPoint.Y;
            return (float)Math.Sqrt(dx * dx + dy * dy);
        }

        /// <summary>
        /// 获取线角度
        /// </summary>
        /// <returns></returns>
        public float GetRotate()
        {
            // 计算向量的 x 和 y 分量
            float dx = endPoint.X - startPoint.X;
            float dy = endPoint.Y - startPoint.Y;
            // 使用 Math.Atan2 函数计算角度（弧度）
            double angleRad = Math.Atan2(dy, dx);
            // 将弧度转换为角度
            float angleDeg = (float)(angleRad * (180 / Math.PI));
            return angleDeg;
        }

        /// <summary>
        /// 获取线中点
        /// </summary>
        /// <returns></returns>
        public PointF GetCenter()
        {
            float x = startPoint.X + (endPoint.X - startPoint.X) / 2;
            float y = startPoint.Y + (endPoint.Y - startPoint.Y) / 2;
            return new PointF(x, y);
        }
    }
}
